﻿using System;
using System.Net;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Collections.Generic;
using Microsoft.Phone.Shell;
using System.Text;

namespace PressureDiary
{
    public class Utility
    {

        public static string getBody(string itemKey)
        {
            StringBuilder buffer = new StringBuilder();
            string[] pairs = itemKey.Split('-');
            int year = Convert.ToInt16(pairs[0]);
            int month = Convert.ToInt16(pairs[1]);

            List<Measure> measures = LoadMeasurementsData(year, month);

            foreach (var item in measures)
            {
                buffer.AppendLine("[" + item.Systolic + "/" + item.Diastolic + "]" + " - " + item.Date.Value.ToLongDateString() + " (@ " + item.TimeMeasure.Value.ToLongTimeString() +")");
            }

            return buffer.ToString();
        }

        private static List<Measure> LoadMeasurementsData(int year, int month)
        {
            List<Measure> list = new List<Measure>();

            using (MyDatabaseContext context = new MyDatabaseContext(MyDatabaseContext.ConnectionString))
            {
                list = context.Measures.Where(x => x.Date.Value.Year == year && x.Date.Value.Month == month).ToList();
                list.Reverse();
            }

            return list;
        }

    }
}
